//
//  LBHomeController.m
//  爱鲜蜂
//
//  Created by 李田 on 16/11/7.
//  Copyright © 2016年 tianyao. All rights reserved.
//

#import "LBHomeController.h"
#import "LBHomeFunctionListView.h"
#import "LBTopNextController.h"
@interface LBHomeController ()

@end

@implementation LBHomeController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(btnClick:) name:@"button" object:nil];
    
    UIBarButtonItem *rightBtnItem = [self barButtonItemWithImageName:@"v2_refresh" tag: kReloadDataButton];
    
    UIBarButtonItem *leftBtnItem = [self barButtonItemWithImageName:@"v2_goback" tag: kBackButton];
    [self.navigationItem setRightBarButtonItem:rightBtnItem];
    
    
    [self.navigationItem setLeftBarButtonItem:leftBtnItem];
}

#pragma mark - 自定义导航条左右按钮
- (UIBarButtonItem *)barButtonItemWithImageName: (NSString *)imageName tag: (TYNextVcTag)tag{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    
    btn.frame = CGRectMake(0, 0, 30, 30);
    
    UIBarButtonItem *btnItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    [btn addTarget:self action:@selector(navBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    btn.tag = tag;
    return btnItem;
    
}


- (void)navBtnClick: (UIBarButtonItem *)btnItem{
    
    
    
}

#pragma mark - 通知
- (void)btnClick: (NSNotification *)no{
    
    LBTopNextController *topNextVc = [[LBTopNextController alloc]init];
    UIButton *btn =  no.object;

    NSString *str = btn.titleLabel.text;
    
//    str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    str = [str stringByReplacingOccurrencesOfString:@"\r" withString:@""];
    str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    [self.navigationController pushViewController:topNextVc animated:YES];
    
    topNextVc.navigationItem.title = str;
    
}


#pragma mark - 1.0 创建collectionView
- (void)setupUI{
    
    
    
    LBHomeFunctionListView *functionView = [[LBHomeFunctionListView alloc] init];
    
    
    [self.view addSubview:functionView];
    
    // 布局
    [functionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(self.view);
    }];
      
}



@end
